package baiqitun.stupro.common.workflow.util;

import org.flowable.engine.RuntimeService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * RuntimeService的封装
 * @author kedaji
 */
@Service
public class RuntimeUtil {
    @Autowired
    private RuntimeService runtimeService;

    /**
     * 启动一个流程
     * @param processDefinitionKey 流程定义key
     * @param businessId 业务id
     * @param variables 流程变量
     * @return 流程实例
     */
    public ProcessInstance startProcessInstanceByKey(@NotBlank(message = "流程定义key不能为空") String processDefinitionKey,
                                                     String businessId, Map<String,Object> variables){
        return runtimeService.startProcessInstanceByKey(processDefinitionKey, businessId, variables);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteProcessInstance(String processInstanceId, String deleteReason){
        runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
    }
}
